// 导入所有工具
import { unique, shuffle, chunk, flatten, merge, get, set, cloneDeep } from './index';

console.log('=== 数组处理示例 ===');

// 数组去重示例
const numbers: number[] = [1, 2, 2, 3, 4, 4, 5];
console.log('原始数组:', numbers);
console.log('去重后:', unique(numbers));

// 数组打乱示例
console.log('打乱后:', shuffle(numbers));

// 数组分割示例
console.log('分割成2个元素一组:', chunk(numbers, 2));

// 数组扁平化示例
const nestedArray: number[][] = [[1], [2, 3], [4]];
console.log('原始嵌套数组:', nestedArray);
console.log('扁平化后:', flatten<number>(nestedArray));

console.log('\n=== 对象处理示例 ===');

// 对象深度合并示例
const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { b: { d: 3 }, e: 4 };
console.log('对象1:', obj1);
console.log('对象2:', obj2);
console.log('合并后:', merge({}, obj1, obj2));

// 获取嵌套属性示例
interface User {
  id: number;
  name: string;
  profile: {
    age: number;
    address: {
      city: string;
      district: string;
      street?: string;
    };
  };
}

const user: User = {
  id: 1,
  name: '张三',
  profile: {
    age: 30,
    address: {
      city: '北京',
      district: '朝阳区',
    },
  },
};
console.log('用户对象:', user);
console.log('获取城市:', get<string>(user, 'profile.address.city'));
console.log('获取不存在的属性(带默认值):', get<string>(user, 'profile.address.street', '未知街道'));

// 设置嵌套属性示例
interface Settings {
  app?: {
    theme?: {
      color?: string;
    };
  };
}

const settings: Settings = {};
set(settings, 'app.theme.color', 'blue');
console.log('设置嵌套属性后:', settings);

// 深拷贝示例
interface OriginalType {
  a: number;
  b: {
    c: number;
  };
}

const original: OriginalType = { a: 1, b: { c: 2 } };
const copy = cloneDeep<OriginalType>(original);
copy.b.c = 999;
console.log('原始对象:', original);
console.log('修改后的拷贝对象:', copy);
